package com.sc.nft.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.UserEcologyPoints;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sc.nft.entity.vo.MyPointsDetailsVO;
import com.sc.nft.entity.vo.UserPointsDetailsStatisticsVO;
import com.sc.nft.entity.vo.ecology.AdminEcologyPointsUserPageVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;

/**
 * 生态-用户积分(sc_user_ecology_points)数据Mapper
 *
 * @author Sun
 * @since 2023-10-13 17:22:12
 * @description 由 Mybatisplus Code Generator 创建
*/
@Mapper
public interface UserEcologyPointsMapper extends BaseMapper<UserEcologyPoints> {

    /**
     * 扣除燃料
     * @param userId
     * @param amount
     * @return
     */
    Boolean subAmount(@Param("userId") Long userId, @Param("amount") BigDecimal amount);

    @Select("select ifnull(sum(amount),0) from sc_user_ecology_points where is_delete = 0")
    BigDecimal getSumAmount();

    /**
     * 分页获取用户燃料
     * @param page
     * @param userTel
     * @return
     */
    Page<AdminEcologyPointsUserPageVO> getUserPage(Page page, @Param("userTel") String userTel);

    /**
     * 获取用户燃料详情
     * @param userTel
     * @return
     */
    UserPointsDetailsStatisticsVO userPointsDetailsStatistics(@Param("userTel") String userTel);

    /**
     * 我的生态燃料详情
     * @param userId
     * @return
     */
    MyPointsDetailsVO myPointsDetails(@Param("userId") Long userId);

    /**
     * 添加金额并且扣除限额
     * @param userId
     * @param amount
     * @return
     */
    Boolean addEcologyPointsAndSubLimit(Long userId, BigDecimal amount);
}
